package cn.tang.tframe.mybatis.spring;

import cn.tang.tframe.common.utils.lang.CollectionUtils;
import cn.tang.tframe.common.utils.lang.SpiUtils;
import org.apache.ibatis.plugin.Interceptor;
import org.mybatis.spring.SqlSessionFactoryBean;

import java.util.List;

/**
 * Created by tanghc on 17/1/12.
 */
public class QtSqlSessionFactoryBean extends SqlSessionFactoryBean {
	@Override
	public void afterPropertiesSet() throws Exception {
		initPlugins();
		super.afterPropertiesSet();
	}
	private void initPlugins(){
		//		将监控相关plugins注入
		List<Interceptor> interceptors = SpiUtils.listSpi(Interceptor.class);
		if(CollectionUtils.isNotEmpty(interceptors)){
			Interceptor[] plugins = new Interceptor[interceptors.size()];
			super.setPlugins(interceptors.toArray(plugins));
		}
	}
}
